#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
       plugin_api.py
       Code is based on Copyright 2009-2014 Giuseppe Penone <giuspen@gmail.com>

       This program is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published by
       the Free Software Foundation; either version 3 of the License, or
       (at your option) any later version.

       This program is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       GNU General Public License for more details.

       You should have received a copy of the GNU General Public License
       along with this program; if not, write to the Free Software
       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
       MA 02110-1301, USA.
"""

# import cherrytree.debug.debug_stuff as debug  # debug output functions for colour logging


class Plugin_API(object):
    """ Plugin api class - used by the pliugins to interact with the app  """

    def __init__(self, appref):
        """ setup the class variables """
        self.app_ref = appref  # store the app ref so it can be used to interact with the app
        self.window_ref = None  # todo needs the window_ref inputting here when the other file is sorted (ui)

# app plugin functions here

    def get_app(self):
        """ :return the app ref """
        return self.app_ref

    def get_window(self):
        """ :return the gtk3 main window ref """
        return self.window_ref

    def get_active_window(self):
        """ :return: the active tab window currently active """
        pass  # todo needs the active window ref passing in to the return

# window plugin functions here

    def create_tab(self, name: str, active=True) -> bool:
        """ create a new empty document tab
        :param name: string - The name off the tab to be used
        :param active: boolean - True = Select the new tab. False = do not select the new tab
        :return: boolean - True = tab was created successfuly. False = tab was not created.
        """
        pass  # todo needs writing

    def create_tab_from_location(self,
                                 location: str,
                                 create=False,
                                 encoding=None,
                                 active=True,
                                 line_position=0,
                                 column_position=0) -> bool:
        """
        :param location: string - the path and filename to the file e.g /home/test.py
        :param create: boolean - True = create the file if not found. False = do not create the file if not found (default)
        :param encoding: the encoding to use. Default = None
        :param active: boolean - True = new tab will be selected (default). False = new tab will not be selected
        :param line_position: int - line position to jump to - default = 0 do not move the cursor
        :param column_position: int - column position to jump to - default = 0 do not move the cursor
        :return: boolean - True = tab created successfuly. False = tab not created for some reason
        """

        pass  # todo needs writing

    def close_tab(self, tab_name: str) -> bool:
        """ If the content is unchanged the tab will be closed straight away.
        If there is unsaved content in the tab, a popup dialog will ask the user to save or canceal the action
        If the user agrees the tab will be closed.
        :param tab_name: string - the name of the tab to be closed
        :return: boolean - True = closed tab. False = tab not found/Closed or user stopped the action
        """

        pass  # todo needs writing

    def close_all_tabs(self) -> bool:
        """ A popup dialog will ask the user if all tabs can be closed, if the user agrees all the tabs will
        be closed.
        :return: boolean - True = all tabs closed. False = tabs not closed due to user stopped the action
        """
        pass  # todo needs writing

    def get_active_tab_name(self) -> str:
        """  get the active tab name
        :return: string - the name of the tab
        """
        pass  # todo needs writing

    def set_active_tab(self, tab) -> bool:
        """
        :param tab:
        :return: boolean - True = tab active. False = tab not active.
        """
        pass  # todo needs writing

    def get_unsaved_documents(self) -> list:
        """
        :return: list - List of the unsaved documents.
        """
        pass  # todo needs writing

# side panel plugin functions here

    def add_side_panel_item(self, item, display_name: str, item_image=None) -> int:
        """ add widget to the side panel with optinal image
        :param item: gtk3 widget reference
        :param display_name: string - the display name
        :param item_image: gtk.Image - image object reference to be passed. Default = None.(no image required)
        :return: side_panel_item_id - int - unigue widget item_id, to be used by the plugin. 0 = widget not added
        """
        pass  # todo needs writing

    def remove_side_panel_item(self, side_panel_item_id: int) -> bool:
        """ Remove the widget from the side panel
        :param side_panel_item_id: int - unigue widget side_panel_item_id passed back from
         add_side_panel_item() function.
        :return:
        """
        pass  # todo needs writing

    def activate_side_panel_item(self, side_panel_item_id: int) -> bool:
        """
        :param side_panel_item_id: unigue widget side_panel_item_id passed back from
         add_side_panel_item() function.
        :return: boolean - True = widget is selected. False = widget not found.
        """
        pass  # todo needs writing

    def state_side_panel_item(self, side_panel_item_id: int, item_state: bool) -> bool:
        """ Change the state of the widget.
        :param side_panel_item_id: int - unigue widget side_panel_item_id passed back from
         add_side_panel_item() function.
        :param item_state: boolean - True = widget visable. False = hide widget
        :return: boolean - True = widget updated. False = widget not found.
        """
        pass  # todo needs writing

# editor plugin functions here

    def cut_clipboard(self) -> bool:
        """ Cut the selected content to the clipboard
        :return: boolean - True = cut. False = nothing selected to cut.
        """
        pass  # todo needs writing.

    def copy_clipbord(self) -> bool:
        """ Copy the selected content to the clipboard
        :return: boolean - True = copy. Fasle = nothing to copy
        """
        pass  # todo needs writing

    def paste_clipboard(self) -> bool:
        """ paste the clipboard contents to the current active document
        :return: boolean - True = pasted ok. False = nothing to paste or no document open
        """
        pass  # todo needs writing

    def delete_selection(self) -> bool:
        """ delete the selected content in the current document
        :return: boolean - True = delete completed. False = nothing to delete
        """
        pass  # todo needs writing

    def select_all(self) -> bool:
        """ select all the content in the document
        :return: boolean - True = selected all. Fasle = nothing to select
        """
        pass  # todo needs writing

    def scroll_to_cursor(self) -> bool:
        """ scoll to the cursor position in the current document
        :return: boolean - True = cursor at the position. Fasle = cursor not moved.
        """
        pass  # todo needs writing

    def set_font(self, default: bool, fontname: str="") -> bool:
        """
        :param default: boolean - True = use default font and ignore the fontname field if filled in.
        False = use the fontname field as the new font to use
        :param fontname: string - Name of the font to be used
        :return: boolean - True font set. False = Font not set
        """
        pass  # todo needs writing

    def setect_lines(self, start_line_number: int, end_line_number: int) -> bool:
        """ select lines from start line number to the end line number. (including the end line number)
        :param start_line_number: int - the start line number to select
        :param end_line_number: int - the end line number to select (0 = select to the end)
        :return: boolean - True = lines selected. False = lines not selected.
        """
        pass  # todo needs writing

    def select_line(self, start_end_line_number: int) -> bool:
        """ Just select one line. Uses the call to select_lines()
        :param start_end_line_number:
        :return: boolean - True = line selected. False = line not selected
        """
        return self.setect_lines(start_end_line_number, start_end_line_number)

    def get_readonly(self) ->bool:
        """
        :return: boolean - True = current seleted document is readonly. Fasle = current seleted document is writeable.
        """
        pass  # todo needs writing

    def is_untouched(self) -> bool:
        """ Has the current document contents changed from the saved version.
        :return: boolean - True = no changes made from the saved version. Fasle = changes made with out saving
        """
        pass  # todo needs writing

    def is_untitled(self) -> bool:
        """ Has the current doument have a title.
        :return: boolean - True = no title. Fasle = has a title.
        """
        pass  # todo needs writing

    def goto_line(self, line_number: int) -> bool:
        """ Move the current document cursor to the line number
        :param line_number: int - Line number to move the cursor to. 0 = last line (end)
        :return: boolean - True = the cursor as moved to the line number. False - the cursor was not moved.
        """
        pass  # todo needs writing.

    def move_cursor_position(self, direction, number_to_move) -> bool:
        """ Move the cursor the number of spaces in the direction choosen
        :param direction: boolean - True = forward. False = backwards.
        :param number_to_move: int - number of spaces to move the cursor
        :return: boolean - True = cursor moved. Fasle = cursor not moved
        """
        pass  # todo needs writing.

    def move_cursor_to_end(self) -> bool:
        """ move the cursor in the current document to the end of line
        :return: boolean - True = cursor moved. False = cursor not moved.
        """
        pass  # todo needs writing

    def move_cursor_to_home(self) -> bool:
        """ move the cursor in the current document to the home of the line.
        :return: boolean - True = cursor moved. False = cursor not moved.
        """
        pass  # todo needs writing